package com.twu.biblioteca;

public class Biblioteca {
    private final Readers readers = new Readers();
    private Books books = new Books();

    public void setBooks(Books books) {
        this.books = books;
    }

    public Books getBooks() {
        return books;
    }

    public String welcomeMessage() {
        return "Welcome to Bilioteca!";
    }

    public String mainMenu() {
        return "Main Menu:\n" +
                "1 - List Books.\n" +
                "2 - Checkout Book.\n" +
                "Input a number to choose, please.";
    }

    public String choose(String choice) {
        String display;
        try{
            int i = Integer.parseInt(choice);
            switch (i) {
                case 1:
                    display = getBooks().showBooks();
                    break;
                case 2:
                    display = getBooks().showBooks();
                    break;
                default:
                    display = "Select a valid option!";
                    break;
            }
        } catch (Exception e){
            display = "Select a valid option!";
        }
        return display;
    }

    public boolean checkout(String bookName, String reader) {
        if (books.contains(bookName) && null == readers.whoIsReading(bookName)){
            readers.getReader(reader).checkout(bookName);
            return true;
        } else {
            return false;
        }
    }

    public void register(Reader reader) {
        readers.add(reader);
    }
}
